﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace WebApplication1
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

       

        protected void Button1_Click(object sender, EventArgs e)
        {
            int username = int.Parse(this.username.Text.Trim());
            string password = this.password.Text.Trim();
            int identity = 0;

            if (identiy.SelectedValue == "管理员")
            {
                identity = 1;
            }else if(identiy.SelectedValue == "分销商")
            {
                identity = 2;
            }
            string connStr = "data source=121.43.119.97;user id=root;password=h666niub;database=ticket_management_system;pooling=true;charset=utf8;";
            MySqlConnection conn = new MySqlConnection(connStr);
            conn.Open();
            try
            {
                string find_identity = "SELECT * from identity";
                MySqlCommand cmd_identity = new MySqlCommand(find_identity,conn);
                cmd_identity.ExecuteScalar();



                string insertStr = "INSERT INTO  user(username,password,identity_id)" +
                    "VALUES ('" + username + "','" + password + "','" + identity + "')";
                MySqlCommand cmd = new MySqlCommand(insertStr, conn);
                
                //通过sql语句对表添加数值
                
                if (Convert.ToInt32(cmd.ExecuteScalar()) > 0)
                {
                    MessageBox.Show("登录成功！");
                    /*this.DialogResult = DialogResult.OK;
                      this.Dispose();
                      this.Close();*/
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString() + "打开数据库失败");
            }


        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}